//
//  HomeTableViewCell.m
//  EasyToTesco
//
//  Created by mc on 16/1/31.
//  Copyright © 2016年 Jack. All rights reserved.
//

#import "HomeTableViewCell.h"
#import "CWStarRateView.h"
#import "HeaderFileForEasyToTesco.h"

#define CELLMARC 10
#define SHOPFONT 16
#define CELLFONT 12
#define DISCOUNTFONT 18
#define CELLHEIGH 40

@interface HomeTableViewCell()
{
    UILabel *label1;
    UILabel *label2;
}


@end

@implementation HomeTableViewCell

- (void)awakeFromNib {
    // Initialization code
    
    
}

//
//- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
//    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
//    if (self) {
////        self.contentView.layer.cornerRadius = 5;
////        self.contentView.layer.masksToBounds = YES;
////        self.contentView.layer.borderWidth = 1;
////        [self addHomeCellUI];
//        
//    }
//    return self;
//}
/*
- (void)addHomeCellUI {
    self.picImage = [[UIImageView alloc] init];
    self.picImage.layer.borderWidth = 1;
    [self.contentView addSubview:self.picImage];
    
    self.shopTitle = [[UILabel alloc] init];
    self.shopTitle.font = [UIFont systemFontOfSize:SHOPFONT];
    [self.contentView addSubview:self.shopTitle];
    self.shopTitle.layer.borderWidth = 1;
    
    self.shopLocation = [[UILabel alloc] init];
    self.shopLocation.font = [UIFont systemFontOfSize:SHOPFONT];
    [self.contentView addSubview:self.shopLocation];
    self.shopLocation.layer.borderWidth = 1;
    
    self.puniShment = [[UILabel alloc] init];
    self.puniShment.backgroundColor  = [UIColor blueColor];
    self.puniShment.textColor = [UIColor whiteColor];
    self.puniShment.font = [UIFont systemFontOfSize:SHOPFONT-1];
    [self.contentView addSubview:self.puniShment];
    self.puniShment.layer.borderWidth = 1;
    
    self.location = [[UITextField alloc] init];
    [self setLeftViewWithTextField:self.location imageName:@"location-gray-icon.png"];
    self.location.enabled = NO;
    self.location.font = [UIFont systemFontOfSize:CELLFONT];
    [self.contentView addSubview:self.location];
    self.location.layer.borderWidth = 1;
    
    self.shopStar = [[CWStarRateView alloc] initWithFrame:CGRectNull numberOfStars:5];
    self.shopStar.scorePercent = 0.3;
//    self.shopStar.delegate = self;
    self.shopStar.allowIncompleteStar = YES;
    self.shopStar.hasAnimation = YES;
    [self.contentView addSubview:self.shopStar];
    self.shopStar.layer.borderWidth = 1;

    self.personPrice = [[UILabel alloc] init];
    self.personPrice.font = [UIFont systemFontOfSize:CELLFONT];
    [self.contentView addSubview:self.personPrice];
    self.personPrice.layer.borderWidth = 1;
    
    self.shopStyle = [[UILabel alloc] init];
    self.shopStyle.font = [UIFont systemFontOfSize:CELLFONT];
    [self.contentView addSubview:self.shopStyle];
    self.shopStyle.layer.borderWidth = 1;
    
    self.NumOfPerson = [[UILabel alloc] init];
    self.NumOfPerson.font = [UIFont systemFontOfSize:CELLFONT];
    [self.contentView addSubview:self.NumOfPerson];
    self.NumOfPerson.layer.borderWidth = 1;
    
    self.NumOfBuy = [[UITextField alloc] init];
    [self setLeftViewWithTextField:self.NumOfBuy imageName:@"men-gray-icon.png"];
    self.NumOfBuy.textColor = [UIColor greenColor];
    [self.contentView addSubview:self.NumOfBuy];
    self.NumOfBuy.layer.borderWidth = 1;
    
    label1 = [[UILabel alloc] init];
    label1.font = [UIFont systemFontOfSize:CELLFONT];
    label1.text = @"人购买";
    [self.contentView addSubview:label1];
    label1.layer.borderWidth = 1;
    
    self.DiscountLabel = [[UILabel alloc] init];
    self.DiscountLabel.font = [UIFont systemFontOfSize:DISCOUNTFONT];
    self.DiscountLabel.textColor = [UIColor redColor];
    [self.contentView addSubview:self.DiscountLabel];
    self.DiscountLabel.layer.borderWidth = 1;
    
    label2 = [[UILabel alloc] init];
    label2.font = [UIFont systemFontOfSize:CELLFONT];
    label2.text = @"折";
    [self.contentView addSubview:label2];
    label2.layer.borderWidth = 1;
    
    
    

}

- (void)layoutSubviews {
    [super layoutSubviews];
    CGFloat imageheigh = (CELLHEIGH/2)*3 + CELLMARC*2 + CELLHEIGH;
    
    self.picImage.frame = CGRectMake(CELLMARC*WEITHRATE, CELLMARC*HIGHTRATE, (imageheigh+imageheigh/4)*WEITHRATE, imageheigh*HIGHTRATE);
    
    CGFloat otherMarc = (CGRectGetMaxX(self.picImage.frame)+5)*WEITHRATE;
    
    self.shopTitle.frame = CGRectMake(otherMarc, CELLMARC*HIGHTRATE, 80, CELLHEIGH*HIGHTRATE);
    self.shopLocation.frame = CGRectMake(CGRectGetMaxX(self.shopTitle.frame)+5, CELLMARC*HIGHTRATE, 120, CELLHEIGH*HIGHTRATE);
    self.puniShment.frame = CGRectMake(CGRectGetMaxX(self.shopLocation.frame), CELLMARC*HIGHTRATE, CELLHEIGH*HIGHTRATE, CELLHEIGH*HIGHTRATE);
    self.location.frame = CGRectMake(CGRectGetWidth(self.contentView.frame)-100, CELLMARC*3*HIGHTRATE, 80, CELLHEIGH/2*HIGHTRATE);
    self.shopStar.frame = CGRectMake(otherMarc, (CGRectGetMaxY(self.shopTitle.frame)+CELLMARC/2)*HIGHTRATE, 100, (CELLHEIGH/2)*HIGHTRATE);
    self.personPrice.frame = CGRectMake(CGRectGetMaxX(self.shopStar.frame), CGRectGetMinY(self.shopStar.frame)*HIGHTRATE, 120, (CELLHEIGH/2)*HIGHTRATE);
    self.shopStyle.frame = CGRectMake(otherMarc, (CGRectGetMaxY(self.shopStar.frame)+CELLMARC/2)*HIGHTRATE, 40, (CELLHEIGH/2)*HIGHTRATE);
    self.NumOfPerson.frame = CGRectMake(CGRectGetMaxX(self.shopStyle.frame), (CGRectGetMaxY(self.shopStar.frame)+CELLMARC/2)*HIGHTRATE, 100, (CELLHEIGH/2)*HIGHTRATE);
    self.NumOfBuy.frame = CGRectMake(otherMarc, (CGRectGetMaxY(self.NumOfPerson.frame)+CELLMARC/2)*HIGHTRATE, 100, (CELLHEIGH/2)*HIGHTRATE);
    label1.frame = CGRectMake(CGRectGetMaxX(self.NumOfBuy.frame), CGRectGetMinY(self.NumOfBuy.frame)*HIGHTRATE, 30, CGRectGetHeight(self.NumOfBuy.frame)*HIGHTRATE);
    self.DiscountLabel.frame = CGRectMake(CGRectGetWidth(self.contentView.frame)-100, (CGRectGetMaxY(self.shopStar.frame)+CELLHEIGH/2)*HIGHTRATE, 70, (CELLHEIGH+CELLMARC/2)*HIGHTRATE);
    label2.frame = CGRectMake(CGRectGetMaxX(self.DiscountLabel.frame), CGRectGetMinY(self.NumOfBuy.frame)*HIGHTRATE, 20, (CELLHEIGH/2)*HIGHTRATE);
    
    
}

 */
/**
 *  给UITextField设置右侧的图片
 *
 *  @param textField UITextField
 *  @param imageName 图片名称
 */

//-(void)setLeftViewWithTextField:(UITextField *)textField imageName:(NSString *)imageName{
//    
//    UIImageView *rightView = [[UIImageView alloc]init];
//    
//    rightView.image = [UIImage imageNamed:imageName];
//    rightView.frame = CGRectMake(0, 0, CGRectGetHeight(textField.frame), CGRectGetHeight(textField.frame));
//    rightView.contentMode = UIViewContentModeCenter;
//    textField.leftView = rightView;
//    textField.leftViewMode = UITextFieldViewModeAlways;
//}
//
//
//- (void)drawRect:(CGRect)rect {
//    [self changeFrame];
//}
//
////frame调整
//- (void)changeFrame {
//    //    cell = [[[NSBundle mainBundle]loadNibNamed:@"HomeTableViewCell" owner:nil options:nil] lastObject];
//    CGRect shoptitleRect = [self.shopTitle.text boundingRectWithSize:CGSizeMake(1000, 1000) options:NSStringDrawingUsesLineFragmentOrigin attributes:[NSDictionary dictionaryWithObjectsAndKeys:self.shopTitle.font,NSFontAttributeName, nil] context:nil];
//    self.shopTitle.frame = CGRectMake(CGRectGetMinX(self.shopTitle.frame),self.shopTitle.frame.origin.y, shoptitleRect.size.width, self.shopTitle.frame.size.height);
//    
//    CGRect shoplocationRect = [self.shopLocation.text boundingRectWithSize:CGSizeMake(1000, 1000) options:NSStringDrawingUsesLineFragmentOrigin attributes:[NSDictionary dictionaryWithObjectsAndKeys:self.shopLocation.font,NSFontAttributeName, nil] context:nil];
//    self.shopLocation.frame = CGRectMake(self.shopTitle.frame.origin.x+shoptitleRect.size.width, self.shopLocation.frame.origin.y, shoplocationRect.size.width, self.shopLocation.frame.size.height);
//    
//    self.personPrice.frame = CGRectMake(CGRectGetMaxX(self.shopStar.frame), CGRectGetMinY(self.personPrice.frame), CGRectGetWidth(self.personPrice.frame), CGRectGetHeight(self.personPrice.frame));
////    NSLog(@"%lf,,,,,%lf,,,,,%lf,,,,%lf", self.shopTitle.frame.origin.x, self.shopTitle.frame.size.width, self.shopLocation.frame.origin.x, shoptitleRect.size.width);
//    
//    CGRect shopstyleRect = [self.shopStyle.text boundingRectWithSize:CGSizeMake(1000, 1000) options:NSStringDrawingUsesLineFragmentOrigin attributes:[NSDictionary dictionaryWithObjectsAndKeys:self.shopStyle.font,NSFontAttributeName, nil] context:nil];
//    self.shopStyle.frame = CGRectMake(CGRectGetMinX(self.shopStyle.frame), CGRectGetMinY(self.shopStyle.frame), shopstyleRect.size.width, CGRectGetHeight(self.shopStyle.frame));
//    
//    CGRect NumOfpersonRect = [self.NumOfPerson.text boundingRectWithSize:CGSizeMake(1000, 1000) options:NSStringDrawingUsesLineFragmentOrigin attributes:[NSDictionary dictionaryWithObjectsAndKeys:self.NumOfPerson.font,NSFontAttributeName, nil] context:nil];
//    self.NumOfPerson.frame = CGRectMake(CGRectGetMaxX(self.shopStyle.frame), self.NumOfPerson.frame.origin.y, NumOfpersonRect.size.width, self.NumOfPerson.frame.size.height);
//    
//    
//    CGRect NumOfbuyRect = [self.NumOfBuy.text boundingRectWithSize:CGSizeMake(1000, 1000) options:NSStringDrawingUsesLineFragmentOrigin attributes:[NSDictionary dictionaryWithObjectsAndKeys:self.NumOfBuy.font,NSFontAttributeName, nil] context:nil];
//    self.NumOfBuy.frame = CGRectMake(self.NumOfBuy.frame.origin.x, self.NumOfBuy.frame.origin.y, NumOfbuyRect.size.width, self.NumOfBuy.frame.size.height);
//    
//}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}



@end
